<template>
  <div class="page">
    <!-- 表单 -->

    <a-card>
      <com-vxe-table
        :columns="columns"
        :axios="page"
        :fromItem="fromItem"
        :formData="formData"
        :initialize="initialize"
        @check-view="checkView"
        ref="xTable"
      >
        <template #button>
          <vxe-button
            title="添加"
            status="primary"
            content="添加"
            @click="handlerFormAdd"
          ></vxe-button>
        </template>
        <template #operate="data">
          <div>
            <vxe-button
              title="编辑"
              status="primary"
              content="编辑"
              @click="data.callback(data.row)"
            ></vxe-button>
            <vxe-button
              title="删除"
              content="删除"
              @click="deleteByIds(data.row)"
            ></vxe-button>
          </div>
        </template>
      </com-vxe-table>
    </a-card>
    <year-model
      ref="model"
      @year-save="yearSave($event, '0')"
      @year-submit="yearSave($event, '1')"
      @year-change="yearChange"
    >
      <template #default>
        <everday-form
        ref="form"
          :beforeCreate="beforeCreate"
          :formItem="formItem"
        ></everday-form>
      </template>
    </year-model>
  </div>
</template>
<!-- 

  工作单位  fgzdw

  年度述职报告 fndszbg  大文本
  用户名称 fusermc

  年度：fyear

  fywflcode：业务编码
  fzjjssj  总结结束时间
  fzjkssj：总结开始时间
  submitFlag：0保存
  submitFlag 1提交1
 -->
<script>
const formItem = [
  {
    label: "用户名称",
    model: "fusermc",
    type: "input",
    disabled:true,

  },
  {
    label: "工作单位",
    model: "fgzdw",
    type: "input",
    disabled:true
  },
  {
    label: "年度",
    model: "fyear",
    type: "input",
  },
  {
    label: "选派次数",
    model: "fzxxpcs",
    type: "number",
  },
  {
    label: "审评次数",
    model: "fsjjccs",
    type: "number",
  },
  // {
  //   label: "总结开始时间",
  //   model: "fzjkssj",
  //   type: "datetime",
  //   format:'YYYY-MM-DD',
  //   disabled:true
  // },
  {
    label: "总结结束时间",
    model: "fzjjssj",
    type: "datetime",
    format:'YYYY-MM-DD'
  },
  {
    label: "年度述职报告",
    model: "fndszbg",
    type: "textarea",
    toHeight:true,
    style:{
      height:'200px',
    }
  },
];
// 待考评
import {
  scqueryPageList,
  deleteMyNdkpJbxx,
  openMyNdkpJbxx,
  djNdkpJob,
} from "../../api/yearCheck";
import comVxeTable from "@/views/everydayCheck/components/vxe-table/com-vxe-table";
import YearModel from "../../components/yearCheck/year-model.vue";
import everdayForm from "../../components/everday-form.vue";
import { pick } from "../../utils/utils";
import moment from "moment";
export default {
  components: { comVxeTable, YearModel, everdayForm },
  name: "dengjiPage",
  props: {
    fywflcode: {
      type: String,
      default() {
        return "";
      },
    },
  },
  data() {
    return {
      formItem,
      columns: [
        {
          type: "checkbox",
        },
        {
          type: "seq",
          title: "序号",
          width: "60",
        },
        {
          field: "fusermc",
          title: "用户名称",
          width: "150",
        },
        {
          field: "fgzdw",
          title: "工作单位",
          width: "150",
        },
        {
          field: "fyear",
          title: "年度",
          width: "150",
        },
        {
          field: "fzjkssj",
          title: "总结开始时间",
          width: "150",
        },
        {
          field: "fzjjssj",
          title: "总结结束时间",
          width: "150",
        },
        {
          field: "fsftjkh",
          title: "是否提交考核",
          width: "150",
        },

        {
          title: "操作",
          field: "operate",
          width: 200,
          slots: { default: "operate", fixed: "right" },
          fixed: "right"
        },
      ],
      queryParams: {},
      config: {},
      data: [],
      allAlign: null,
      formData: {
        fsxmc: "",
        fqymc: "",
        fslsj: "",
        fjzrq: "",
      },
      fromItem: [
        {
          field: "fyear",
          title: "年度",
          type:'input',
          itemRender: {},
          slots: { default: "name_item" },
        },
        {
          field: "fzjjssj",
          type:'datetime',
          title: "总结开始时间",
          itemRender: {},
          slots: { default: "name_item" },
        },
        {
          field: "fzjkssj",
          type:'datetime',
          title: "总结结束时间",
          itemRender: {},
          slots: { default: "name_item" },
        },
      ],
      page: scqueryPageList,
      initialize: {
        fywflcode: this.fywflcode,
        fsftjkh: "否",
      },
      // fndszbg 填写 大文本
      form: {},
      model: {},
      timeout: null,
      djNdkpJob_id:'' //编辑 添加年度表单临时存储id变量
    };
  },
  created() {
    
  },

  mounted() {},

  methods: {
    // 编辑
    checkView(row) {
      openMyNdkpJbxx({ ndkpid: row.id })
        .then((res) => {
          if (res.success) {
            this.$refs.model.handler(res.result);
            this.timeout = setTimeout(() => {
              this.form.setFieldsValue(
                pick(Object.keys(res.result), res.result)
              );

              if (this.timeout) clearTimeout(this.timeout);
            }, 0);
          } else {
            this.$message.error(res.message);
          }
        })
        .catch((error) => {
          this.$message.error("未知异常");
        });
    },
    // 删除
    deleteByIds(row) {
      deleteMyNdkpJbxx({ ndkpid: row.id }).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
          this.$refs.xTable.getQueryList({ page: {}, form: {} });
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 添加
    handlerFormAdd() {
      this.djNdkpJob_id = ""
      this.$refs.model.handler();
      let timeout = setTimeout(() => {
        this.$refs.form.form.setFieldsValue({

        })
      }, 0);
    },
    // 表单
    beforeCreate(form) {
      this.form = form;
    },
    yearChange(params) {
      this.model = Object.assign(this.model, params);
    },
    // 保存-添加
    yearSave(event = {}, str) {
      this.form.validateFields((error, values) => {
        if (!error) {
          let params = Object.assign(this.model, this.initialize);
          const formData = Object.assign(params, values);
          formData.submitFlag = str;
          formData.id = event["id"] || this.djNdkpJob_id;
          djNdkpJob(formData).then((res) => {
            const { result } = res;
            if (result) {
              this.djNdkpJob_id = result
              this.$VxeMessage({ content: res.message, status: 'success' })
            } else {
              this.$VxeMessage({ content: res.message, status: 'error' })
            }
          });
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
// @import "../assets/table.less";
@import url("../../assets/table.less");
</style>
